from config import config
from flask import Flask
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_restplus import Api
from flask import Blueprint


migrate = Migrate()
login_manager = LoginManager()
db = SQLAlchemy()


def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db=db)
    from .apiv1 import blueprint as register_v1
    app.register_blueprint(register_v1)

    return app
